package game.system;

import game.info.*;
import java.io.*;
import java.util.*;

public class MainGame {

	public static void main (String[] args) {
		
		System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
		System.out.println("	You wake up.");
		
		while (Player.getPlayerLocation() <= 3 ) {
			
			while(Player.hasOpenedDoor != true) {
			
				switch (Player.getPlayerLocation()) { //Prints out roomDescriptors for the room the player is in
				
					case 1: System.out.println(Player.getRoomOne());
					case 2: System.out.println(Player.getRoomTwo());
					case 3: System.out.println(Player.getRoomThree());
				
				}
				
				engine();
			
				System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
			
			}
		
			System.out.println("	A strange force compels you to exit the room. The door slams shut behind you.");
			Player.setPlayerLocation(Player.getPlayerLocation() + 1); //Moves player to next room
			Player.setHasOpenedDoor(false); //Resets door to closed
			
		}
		
		System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
		System.out.println("	You wake up.");
		
		switch (Player.getPlayerVerdict()) { //Gives player's ending depending on the player's solutions.
			
			case 3: //Victim Ending
				System.out.println();
				System.out.println();
				System.out.println();
				System.out.println();
				System.out.println();
			case -3: //Guilty Ending
				System.out.println();
				System.out.println();
				System.out.println();
				System.out.println();
				System.out.println();
			default: //Bystander ending
				System.out.println();
				System.out.println();
				System.out.println();
				System.out.println();
				System.out.println();
		
		}
			
	}
		
	// Game engine - common functions
	public static void engine(){
	    System.out.println();
	    System.out.print("    ENTER YOUR COMMAND: ");
		Scanner in = new Scanner(System.in);
		Player.playerInput = in.nextLine();
		in.close();
		direct(Player.playerInput);
	}
	public static void direct(String input){
		String[] verbs = {"look","help","get","use","examine","put","go","combine","hit","open","close","fill"};
		int v = -1;
		
		for (int n=0; n<verbs.length;n++)
			if (input.indexOf(verbs[n]) >= 0)
				v = n;
		if (v > -1){
			switch (v){
			case 0:
				look();
				break;
			case 1:
				help();
				break;
			case 2:
				get();
				break;
			case 3:
				use();
				break;
			case 4:
				examine(input);
				break;
			case 5:
				put(input);
				break;
			case 6:
				go(input);
				break;
			case 7:
				combine(input);
				break;
			case 8:
				hit(input);
				break;
			case 9:
				open(input);
				break;
			case 10:
				close(input);
				break;
			case 11:
				fill(input);
				break;
			}
		}else
			System.out.println("Your command is unintelligable. Type \"help, phrasing\" for more info.");
	}
	public static void help(){
		String input = Player.playerInput;
		input=input.replace("help, ","").replace("Help, ","");
		if (input=="phrasing"||input==""){
			System.out.println("PHRASING\n" +
					"State your actions with at least a VERB, NOUN, and sometimes a SECOND NOUN");
		}
	}
	public static void look(){
		int room = Player.getPlayerLocation();
		String[]    
				items={};
		String[][]  where={{}};
		boolean[][]  shows={{}};
		boolean[][] state={{}};
		switch (room){
		case 1:
			items = Player.items_1;
			where = Player.where_1;
			shows = Player.shows_1;
			state = Player.state_1;
			break;
		case 2:
			items = Player.items_2;
			where = Player.where_2;
			shows = Player.shows_2;
			state = Player.state_2;
			break;
		}
		
		boolean with;
		
		System.out.print("In the room is:");
		for (int n = 0;n<items.length;n++){
			if (where[n][0]=="room"){
				with = true;
				System.out.print("\n - " + items[n]);
				for (int a = 0;a<items.length;a++){
					if (where[a][0]==items[n]&&shows[a][0]){
						if (with){
							System.out.print(" with:");
							with = false;
						}
						System.out.print("\n   - " + items[a]);
					}
				}
			}
		}
	}
	public static void get(){
		String item = Player.playerInput.replace("get", "").trim();
		int room = Player.getPlayerLocation();
		String[]    items={};
		String[][]  where={{}};
		boolean[][]  shows={{}};
		boolean[][] state={{}};
		switch (room){
		case 1:
			items = Player.items_1;
			where = Player.where_1;
			shows = Player.shows_1;
			state = Player.state_1;
			break;
		case 2:
			items = Player.items_2;
			where = Player.where_2;
			shows = Player.shows_2;
			state = Player.state_2;
			break;
		}

		int index = -1;

		boolean inReach = false;
		for (int n = 0; n<items.length; n++)
			if (items[n]=="a "+item){
				index = n;
				inReach = true;
			}
		if (inReach){
			
			if (state[index][0]==false){
				rooms[room][2][0][index]/* [rooms[room][0].indexOf(item)]*/="taken";
				System.out.println("You take the "+item+".");
			}else
				System.out.println("You can not take that with you.");
		}else
			System.out.println("No "+item+" is in reach.");
		return rooms;
	}
	public static void use(){
		String input = Player.playerInput.replace("use", "").trim();
	}
	public static void examine(){
		String input = Player.playerInput;
		
	}
	public static void put(){
		String input = Player.playerInput;
		
	}
	public static void go(){
		String input = Player.playerInput;
		
	}
	public static void combine(){
		String input = Player.playerInput;
		
	}
	public static void hit(){
		String input = Player.playerInput;
		
	}
	public static void open(){
		String input = Player.playerInput;
		
	}
	public static void close(){
		String input = Player.playerInput;
		
	}
	public static void fill(){
		String input = Player.playerInput;
		
	}
}


